package com.cc.controller;

import com.cc.dto.BookParam;
import com.cc.entity.Book;
import com.cc.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    BookService bookService;
    //获取书籍列表
    @RequestMapping("/list")
    public List<Book> list(@RequestBody BookParam bookParam) {
        return bookService.list(bookParam);
    }
    //新增书籍
    @RequestMapping("/add")
    public String add(@RequestBody Book book) {
        return bookService.add(book) > 0 ? "success" : "fail";
    }
    //修改书籍
    @RequestMapping("/update")
    public String update(@RequestBody Book book) {
        return bookService.update(book) > 0 ? "success" : "fail";
    }
    //删除书籍
    @RequestMapping("/delete")
    public String delete(@RequestBody Book book) {
        return bookService.delete(book) > 0 ? "success" : "fail";
    }
}
